//
//  ActiveViewController.m
//  Found
//
//  Created by 唐后能 on 16/4/2.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "XBFindViewController.h"
#import "XBFindViewCell.h"
#import "XBSearchViewController.h"

@interface XBFindViewController ()
// 数据.
@property (nonatomic, strong) NSArray *ArtNames;
// 下拉刷新.
@property (weak, nonatomic) IBOutlet UIRefreshControl *refreshControll;


@end

@implementation XBFindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    NSLog(@"%@",self.ArtNames);
    self.title = @"发现";
    self.tableView.backgroundColor = [UIColor grayColor];
    // 为下拉刷新添加事件.
    [self.refreshControl addTarget:self action:@selector(refreshData:) forControlEvents:UIControlEventValueChanged];
}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.ArtNames.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    XBFindViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"find"];
    cell.imgURLString = self.ArtNames[indexPath.row];
    return cell;
}

#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 160;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"点击了第%ld个cell",indexPath.row);
}

#pragma mark - 点击发现
- (IBAction)search:(UIBarButtonItem *)sender {
    UITableViewController *searchNav= [[UIStoryboard storyboardWithName:@"Search" bundle:nil] instantiateInitialViewController];
    //    [self.navigationController pushViewController:searchNav animated:NO];
    [self presentViewController:searchNav animated:NO completion:nil];
}

#pragma mark - 下拉刷新.
- (void)refreshData:(UIRefreshControl*)refreshControl {

    NSLog(@"更新数据");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.refreshControl endRefreshing];
    });
}

#pragma mark - 懒加载.
- (NSArray *)ArtNames {

    if (_ArtNames==nil) {
        _ArtNames = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"find.plist" ofType:nil]];
    }
    return _ArtNames;
}

@end
